/*
 * Background Flickr: Copyright (C) 2009  Craig McNicholas
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.ddw.app.bflickr;

import java.util.ArrayList;

import com.ddw.app.bflickr.flickr.api.FlickrAccount;
import com.ddw.app.bflickr.flickr.api.utils.EmailAddress;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class FlickrActivity extends Activity {
	
	/**
	 * The flickr accounts overview
	 */
	private FlickrAccountsLinearLayout accounts;
	
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.accounts = new FlickrAccountsLinearLayout(getApplicationContext());
        setContentView(this.accounts);
    }
    
    /**
     * Called when the activity starts.
     */
    @Override
    protected void onStart() {
    	super.onStart();
    	
    	// TODO Get a list of accounts
    	ArrayList<FlickrAccount> flickrs = new ArrayList<FlickrAccount>();
    	flickrs.add(new FlickrAccount("ABCD123", new EmailAddress("fungus1487@yahoo.com")));
    	flickrs.add(new FlickrAccount("KL34FD8", "JOHNCROCKFORD"));
    	flickrs.add(new FlickrAccount("456892A", new EmailAddress("charlottechapman19@yahoo.co.uk")));
    	flickrs.add(new FlickrAccount("73290FD", new EmailAddress("johnbaptist@yahoo.co.uk")));
    	flickrs.add(new FlickrAccount("KL34FD8", "lemonsforsale"));
    	
    	for(int i = 0; i < flickrs.size(); i ++) {
    		final FlickrAccount acc = flickrs.get(i);
    		FlickrAccountListItemRelativeLayout item = new FlickrAccountListItemRelativeLayout(this);
    		item.setHeader(acc.getUsername() != null ? acc.getUsername() : acc.getEmailAddress().toString());
    		item.setText("Last published 12/04/2009 @ 12:45:32 (3 images)");
    		item.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Toast.makeText(getApplicationContext(), "Pressed flickr account with NSID: " + acc.getNSID(), Toast.LENGTH_LONG);
				}
    			
    		});
    		this.accounts.getList().addView(item);
    	}
    }
    
}